#include "scene_node.h"

namespace vortex
{
    SceneNode::SceneNode() : transform(glm::mat4(1.0f))
    {

    }

    void SceneNode::addChild(SceneNode* child)
    {
        child->parent = this;
        children.push_back(child);
    }

    glm::mat4 SceneNode::getAbsoluteTransform()
    {
        SceneNode* node = this->parent;
        glm::mat4 t = this->transform;

        while (node != nullptr)
        {
            t = node->transform * t;
            node = node->parent;
        }
        return t;
    }

    void SceneNode::updateTransform()
    {
        // absolute transformations are calculated on the fly.
        // for (auto& child : children) 
        // {
        //     child.transform = transform * child.transform;
        //     child.updateTransform();
        // }
    }
}

